/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bddfirstproject;

import bddfirstproject.controller.PartieRedactionDAL;
import bddfirstproject.model.Auteur;
import bddfirstproject.model.PartieRedaction;
import bddfirstproject.model.Theme;
import bddfirstproject.view.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.*;

/**
 *
 * @author epulapp
 */
public class MainController extends JFrame {
    
    private static MainController instance;
    public static MainController getInstance() {
        return instance;
    }
    
    protected static final String title = "Polytech News Writer";
    
    protected JPanel currentView;
    protected Auteur currentAuteur;
    protected Theme currentTheme;
    protected PartieRedaction currentArticle;
    protected PartieRedaction currentPartieEdition;
    
    @SuppressWarnings("LeakingThisInConstructor")
    public MainController() {
        super();
        MainController.instance = this;
        
        // Parametres de l'application
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setCurrentView(new ConnectionView());
        
        this.setVisible(true);
        pack();
        setLocationRelativeTo(null);
    }

    public static void main(String[] args) throws SQLException, IOException, Exception {
        new MainController().setVisible(true);
    }
    
    public void setCurrentView(NamedJPanel view) {
        if(this.currentView != null) {
            this.currentView.setVisible(false);
            this.remove(this.currentView);
        }
        this.currentView = view;
        this.add((JPanel)this.currentView);
        this.setTitle(MainController.title + " - " + view.getTitle());
    }
    
    public void setCurrentAuteur(Auteur auteur) {
        this.currentAuteur = auteur;
    }
    
    public Auteur getCurrentAuteur() {
        return this.currentAuteur;
    }
    
    public void setCurrentTheme(Theme theme) {
        this.currentTheme = theme;
    }
    
    public Theme getCurrentTheme() {
        return this.currentTheme;
    }
    
    public void setCurrentArticle(PartieRedaction article) {
        this.currentArticle = article;
    }
    
    public PartieRedaction getCurrentArticle() {
        return this.currentArticle;
    }
    
    public void setCurrentPartieEdition(PartieRedaction partieEdition) {
        this.currentPartieEdition = partieEdition;
    }
    
    public PartieRedaction getCurrentPartieEdition() {
        return this.currentPartieEdition;
    }

    public void exit() {
        dispose();
        System.exit(0);
    }
    
    public static float getCurrentPanelSize() {
        return 1.2f;
    }

    
}
